<?php
class Register extends CI_Controller{
	
	function Register(){
		parent::__construct();
		$this->lang->load('register_validation');
	}
	
	public function index(){
		
		$this->form_validation->set_rules('user', 'lang:user', 'trim|required|min_length[4]|max_length[12]|is_unique[users.username]');
		$this->form_validation->set_rules('pass', 'lang:pass', 'trim|required|matches[cpass]|md5');
		$this->form_validation->set_rules('cpass', 'lang:cpass', 'trim|required');
		$this->form_validation->set_rules('email', 'lang:email', 'trim|required|valid_email|matches[cemail]|is_unique[address.email]');
		$this->form_validation->set_rules('cemail', 'lang:cemail', 'trim|required');
		$this->form_validation->set_rules('fname', 'lang:fname', 'trim|required');
		$this->form_validation->set_rules('lname', 'lang:lname', 'trim|required');
		$this->form_validation->set_rules('address', 'lang:address', 'trim|required');
		$this->form_validation->set_rules('phone', 'lang:phone', 'trim|required|');
		$this->form_validation->set_rules('bio', 'lang:bio', 'trim|required');
		
		if($this->form_validation->run() == FALSE){
			$this->template->write_view('left','front_end/layout/left',NULL,TRUE);
			$this->template->write_view('content','front_end/register/index',NULL,TRUE);
			$this->template->load();
		}else{
			//print_r($this->input->post());
			$this->User_model->register($this->input->post());
		}
	}
		
	private function check_phonenumber($str){
		if(true){
			return TRUE;	
		}
		
		$this->form_validation->set_message('check_phonenumber','Định dạng điện thoại không đúng');
		return FALSE;
	}
}